package com.snmp.test.task;

import com.alibaba.fastjson.JSONObject;
import com.snmp.test.entity.WirelessAlarmData;
import com.snmp.test.snmp.SnmpUtilSendTrap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author WangChao
 * @Description //TODO
 * @Date 18:10 2019/6/14
 * @Param
 * @return
 **/

@Component
@Configuration
//@EnableScheduling
public class Task {

    private static final Logger LOGGER = LoggerFactory.getLogger(Task.class);

    @Autowired
    private SnmpUtilSendTrap snmpUtilSendTrap;


    /**
     * 每15分钟执行: 0 0/15 * * * ?
     * 每十秒执行:  0/10 * * * * ?
     * 每天凌晨1:00点执行 0 0 1 * * ?
     */
    /**
     * 发送snmp
     *
     * @throws Exception
     */
//    @Scheduled(cron = "0 0/1 * * * ?")
//    @Scheduled(cron = "0/10 * * * * ?")
    @Scheduled(cron = "0 0/5 * * * ?")
    public void snmpSendTask() throws Exception {
        LOGGER.info("SnmpUtilSendTrap...start...");
        WirelessAlarmData req = new WirelessAlarmData();
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String nowString = sdf.format(now);
        req.setAckTime(nowString);
        req.setOccurTime(nowString);
        req.setNeType("无线专网");
        req.setAlarmLevel(3);
        req.setAlarmSpecificproblems("设备故障");
        req.setNeIpAddr("10.8.170.129");
        req.setAdditionalInfo("12");
        req.setAlarmCategory("12");
        req.setAlarmConfirm(1);
        req.setAlarmCsn("233");
        req.setAlarmOperator("李四");
        req.setAlarmProbablecause("hahhahhah");
        req.setAlarmProposedrepairactions("233334");
        req.setAlarmRestore(3);
        req.setAlarmType(23);
        req.setAlId("2222");
        req.setClearCategory("54545");
        req.setClearOperator("张三");
        req.setCreateTime(now);
        req.setUpdateTime(now);
        req.setServiceAffectFlag("123231231");
        req.setRestoreTime(nowString);
        req.setProductId(232);
        req.setObjectInstanceType("445");
        req.setNeDevId("4532");
        req.setMoName("jsjfef");
        req.setId(23);
        req.setExtendInfo("wefrwe");
        req.setDevCsn("ewe");
        req.setClearType("2323");

        String jsonString = JSONObject.toJSONString(req);
        LOGGER.info(jsonString);
        snmpUtilSendTrap.initComm();
        snmpUtilSendTrap.sendPDU(req);
        LOGGER.info("SnmpUtilSendTrap...end...");
    }
}
